<template>
  <el-container>
    <!-- 头部 -->
    <el-header>
      <div class="left">
<!--        <img src="../assets/imgs/shop.png" alt="" />-->
        <span>商城后台管理系统</span>
      </div>
      <div class="right">
        <span>欢迎您：{{ username }}</span>
        <el-button type="danger" size="mini" @click="logout">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <!-- 切换菜单的折叠和显示 -->
        <div class="toggle-button" @click="isCollapse=!isCollapse">|||</div>
        <!-- 侧边栏菜单 -->
        <el-menu :default-active="$route.path" unique-opened router :collapse="isCollapse" :collapse-transition="false">
          <el-submenu :index="item.id + ''" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i :class="item.icon"></i><span>{{ item.authName }}</span>
            </template>
            <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <i class="el-icon-menu"></i>{{ subItem.authName }}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main style="background: #f1f1f1;padding: 0px 0px;">
        <div style="height:50px;width: 100%;background: #ffffff;box-shadow:0 1px 4px rgb(0 21 41 / 8%);">
          <breadcrumb id="breadcrumb-container" />
        </div>
        <router-view style="padding: 10px 10px;"></router-view>
        <div style="display:none ">
          <audio :src="require('@/assets/tip.mp3')" :autoplay="false" ref="audio2"></audio>
        </div>
        <div style="display:none ">
          <audio :src="require('@/assets/tip_mc.mp3')" :autoplay="false" ref="audio3"></audio>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import Api from '@/api/Api.js'
let thisVm = null;
export default {
  components:{
    breadcrumb:()=> import('./common/Breadcrumb'),
  },
  data() {
    return {
      username: '',
      menuList: [],
      // 是否折叠左侧的菜单
      isCollapse:false
    };
  },
  created() {
    this.username = localStorage.getItem("username");
    this.getMenuList();
  },
  mounted() {
    thisVm = this
  },
  methods: {
    // 退出
    logout() {
      this.$confirm("确定要退出登陆吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          sessionStorage.clear();
        localStorage.removeItem("userId");
        localStorage.removeItem('uuid');
        localStorage.removeItem('username');
          this.$router.push("/login")
        })
        .catch(() => {
          //   this.$message({
          //     type: "info",
          //     message: "已取消退出",
          //   });
        });
    },
    // 获取左侧的菜单列表
    // async getMenuList() {
    //   const { data: res } = await this.$http.get("menus")
    //   // console.log(res)
    //   if (res.meta.status !== 200) {
    //     return this.$message.error(res.meta.msg)
    //   }
    //   this.menuList = res.data
    // //   console.log(this.menuList)
    // },
    async getMenuList() {
        Api.getLoginUserMenuList({}).then(res => {
            if (res.success) {
                this.menuList = res.data
            } else {
                return this.$message.error('获取权限列表失败')
            }
        })
    }
  }
};
</script>

<style lang="less" scoped>

.breadcrumb-container {
  float: left;
}
.el-container {
  height: 100%;
}
.el-header {
  /*background: url("../assets/imgs/header_bg.gif") repeat-x center;*/
  background: #60779d;
  height: 60px !important;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;

  .left {
    display: flex;
    align-items: center;
    /*img {*/
    /*  width: 40px;*/
    /*  margin-right: 20px;*/
    /*}*/
    span {
      font-size: 24px;
      margin-left: 10px;
    }
  }
  .right {
    span {
      margin-right: 10px;
    }
  }
}
.el-aside {
  .el-menu {
    border-right: 0;
    .iconfont {
      margin-right: 10px;
    }
  }
  .toggle-button{
      background: #60779d;
      font-size: 10px;
      line-height: 24px;
      text-align: center;
      color: white;
      letter-spacing: 0.2rem;
      cursor: pointer;
  }
}
.el-main{
    background: #ffffff;
}
</style>
